<?php

class SaleController extends RController
{
	public $pageTitle = 'Bán hàng';

    public function actionIndex()
	{
        if( !empty($_POST['next']) )
        {
            $this->redirect('ban-hang/xac-nhan');
        }
        $sale = new Sale();
        $data = $sale->getAllItemsAndCoupons();

		$dataProvider = new CArrayDataProvider($data,array(
            'id'        => 'item_id',
            'keyField'  => 'item_id'
        ));

		$this->render('index', array(
            'dataProvider' 		=> $dataProvider,
            'subTotal'			=> $sale->getSubTotal()
        ));
	}

    public function actionConfirm()
    {
        if( !empty($_POST['coupon']) )
        {
            $this->redirect('ban-hang/phieu-giam-gia');
        }
        elseif( !empty($_POST['next']) )
        {
            $this->redirect('ban-hang/xuat-hoa-don');
        }
        $this->render('confirm');
    }

    public function actionCoupon()
    {
        
    }

    public function actionFinish()
    {
        $sale = new Sale();
        $sale->generateOrder();
    }

	public function filters()
	{
		return array(
			'rights'
		);
	}

}